//一星 https://iai.sh.cn/problem/677
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  int king = 0;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    if (a - b > king)
      king = a - b;
    // king = max( king , a-b);
    sum += b;
  }
  cout << sum + king;

  return 0;
}